package com.gtl.meishi.model;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.util.Log;

import com.gtl.meishi.bean.CotegroyEntity;
import com.gtl.meishi.bean.MediaEntity;
import com.gtl.meishi.fragment.HotFragment1;
import com.gtl.meishi.util.JsonUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zhangke on 16/7/9.
 */
public class MediaModel {

    /**
     * @param handler
     * @param path
     * 获取分类
     *
     */
    public  static  void   getCotegory(final Handler handler, final String path, final Context context){

        new Thread(new Runnable() {
            @Override
            public void run() {
            List<CotegroyEntity> listCotegroy= JsonUtil.getCotogroy(path,context);
                Message msg=handler.obtainMessage(0,listCotegroy);
                handler.sendMessage(msg);
            }
        }).start();
    }



    /**
     * @param list
     * @return
     * 根据标题栏个数创建fragment;
     */
//    public  static   List<HotFragment>  getFragement(List<CotegroyEntity> list){
//
//        List<HotFragment> fragmentList=new ArrayList<>();
//        for (int i = 0; i <list.size() ; i++) {
//            HotFragment hotFragment=new HotFragment();
//            hotFragment.setCotegroyEntity(list.get(i));
//            fragmentList.add(hotFragment);
//        }
//        return  fragmentList;
//    }
    public  static   List<HotFragment1>  getFragement(List<CotegroyEntity> list){

        List<HotFragment1> fragmentList=new ArrayList<>();
        for (int i = 0; i <list.size() ; i++) {
            HotFragment1 hotFragment=new HotFragment1();
            hotFragment.setCotegroyEntity(list.get(i));
            fragmentList.add(hotFragment);
        }
        return  fragmentList;
    }

    /**
     * @param handler
     * @param path
     * 获取列表
     *
     */
    public  static  void   getList(final Handler handler, final String path, final Context context, final int page, final CotegroyEntity cotegroyEntity){

        Log.i("TAG",path);
        new Thread(new Runnable() {
            @Override
            public void run() {
                List<MediaEntity> MediaEntity= JsonUtil.getMediaEntity(path,context,page,cotegroyEntity);
                Log.i("TAG","model-getHot"+MediaEntity.size());
                Message msg=handler.obtainMessage(0,MediaEntity);
                handler.sendMessage(msg);
            }
        }).start();
    }
    public  static  void   getListOne(final Handler handler, final String path, final Context context, final int page, final CotegroyEntity cotegroyEntity){

        Log.i("TAG",path);
        new Thread(new Runnable() {
            @Override
            public void run() {
                List<MediaEntity> MediaEntity= JsonUtil.getMediaEntityOne(path,context,page,cotegroyEntity);
                Log.i("TAG","model-getHot"+MediaEntity.size());
                Message msg=handler.obtainMessage(1,MediaEntity);
                handler.sendMessage(msg);
            }
        }).start();
    }


}
